import React,{FC,useState} from 'react';
import { connect, useIntl,IGetInitialProps,useSelector,useDispatch } from 'umi';
import {selectAll} from '@/models/commonModel'
import {OperateServe} from '@/commonServe'
import {setCookie} from '@/utils/cookie'
import { Button } from 'antd';

const token = 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTYyNzA1MzA2OCwiY3JlYXRlZCI6MTYyNzAzMTQ2ODE3MSwib3JnX2lkIjowfQ.NnGwp0f-gLnddFdtm-HNaEhdmg7Y-7LfJyJc2fT5nAH26Lm_jVVjRaSfeEsaWXkhEAoA67GIcGFuqzhbrRQh0A'

interface FCc<T> extends FC<T>{
  getInitialProps:IGetInitialProps
}

const Home:FCc<any> = (props) => {
  // const { title } = props;
  const [title, settitle] = useState<string>('qqqqqqq');
  const {commonState} = useSelector(selectAll)
  const [dataList, setdataList] = useState<any>();
  const dispatch = useDispatch();

  const changeLangs = ()=>{
    setCookie('token',token)
    dispatch({
      type:'commonState/query'
    })
  }

  const handleAjax = ()=>{
    OperateServe.post_opeIncomeMaterialRecord_findPage({"current":1,"pageSize":10,"pageNum":1}).then(res=>{
      setdataList(res.data.content)
    })
  }

  return (
    <div>
      <h1>{title}</h1>
      <h2>{commonState.name}</h2>
      <Button onClick={changeLangs}>切换语言222</Button>
      <p></p>
      <Button onClick={handleAjax}>测试ajax</Button>
      <p>
        {JSON.stringify(dataList)}
      </p>
    </div>
  )
}
Home.getInitialProps = (async ({ store, isServer, history, match, route }) => {
  // console.log(ctx);
  if (!isServer) { return }
  await store.dispatch({ type: 'test/test' })
  return { }
})

export default Home
